package itsur.arquitecturas.implicitinvocation;

/**************************************************************************************
** Class name: CommonData
** Author: A.J. Lattanze
** Date: 12/29/99
** Version 1.0
***************************************************************************************
** Purpose: Assignment 3 for SE 17-655, Architectures for Software Systems.
** This class contains data that is used (directly or indirectly) by all classes
**
** Abstract:  This class instantiates and initializes the common data structures. The
** constructors initialize the course and student lists.  It also creates a list to
** store the list of components.  This class also provides the following methods to
** facilitate inter-object communication:
**
** public void RegisterComponent( Communication Component )
** 	Registers system components by adding them to the list of components.
**
** public Communication GetComponent( String ComponentName )
**	Returns the component object based on the declared name of the object.
**
** public Integer GetComponentID( String ComponentName )
**	Returns the component's ID based on the declared name of the object.
**
** Modification Log
**************************************************************************************
**
**************************************************************************************/

public class CommonData
{
	private String DefaultCourseFile  = "src/itsur/arquitecturas/implicitinvocation/Courses.txt";
	private String DefaultStudentFile = "src/itsur/arquitecturas/implicitinvocation/Students.txt";
	private static boolean Initialized = false;

	static CourseReader TheListOfCourses;
	static StudentReader TheListOfStudents;

	private static ComponentList SystemComponents;

	// This constructor initializes the student and course list using the
	// default lists

	public CommonData()
	{
		if ( !Initialized )
		{
			Initialized = true;

			TheListOfCourses  = new CourseReader( DefaultCourseFile );
			TheListOfStudents = new StudentReader( DefaultStudentFile );
			SystemComponents = new ComponentList();

		} // if

		// If either of these are null, you are in trouble.  In practice there
		// should be some more robust error handling here, but this at least lets
		// you know when the read failed.

		if ( TheListOfCourses.ListOfCourses == null )
		{
			System.out.println( "\n\n *** The course list is empty ***" );

		} // if

		if ( TheListOfStudents.ListOfStudents == null )
		{
			System.out.println( "\n\n *** The student list is empty ***" );

		} // if

	} // Initialize using default input files

	// The following method updates an internal list of system components.  This
	// lets system components know the identity of other components in the system

	public void RegisterComponent( Communication Component )
	{
		SystemComponents.AddComponent( Component );

	} // RegisterComponent

	// This method will return the object that corrisponds to the object's
	// instance name

	public Communication GetComponent( String ComponentName )
	{
		return( SystemComponents.GetComponent( ComponentName ));

	} // GetComponent

	// This method will return the object's registration ID that corrisponds to the
	// object's instance name

	public Integer GetComponentID( String ComponentName )
	{
		return( SystemComponents.GetComponentID( ComponentName ) );

   	} // GetComponentID

} // Class